﻿@{
}
<section class="container-fluid m15_t">
    <div class="data-wrap case">
        <form class="form-inline" id="formSearch">
            <div class="data-tool clearfix">
                <div class="pull-left form-inline ">
                    <a class="btn btn-default btn-sm depositOrderdExport m10_l" href="javascript:void(0)" data-title="导出">导出</a>
                </div>
                <div class="pull-right">

                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l gettext">通知状态：</label>
                        <select class="form-control gettext" name="noticeStatus">
                            <option value="">请选择</option>
                            <option value="1">未通知</option>
                            <option value="2">通知成功</option>
                            <option value="3">通知失败</option>
                            <option value="4">通知中</option>
                        </select>
                    </div>
                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l gettext">支付状态：</label>
                        <select class="form-control gettext" name="status">
                            <option value="">请选择</option>
                            <option value="1">未支付</option>
                            <option value="2">支付成功</option>
                        </select>
                    </div>
                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l">商户订单号：</label>
                        <input class="form-control" name="MerchantOrderNo" type="text" autocomplete="off">
                    </div>

                    <button type="button" class="btn btn-default btn-sm active gettext" id="btnSearch">搜索</button>
                    <button type="button" class="btn btn-default btn-sm gettext" id="AdvSearch">高级搜索</button>

                </div>
            </div>
            <!--一高级搜索开始-->
            <div class="AdvSearch">
                <div class="AdvSearchcom collapse">
                    <table>
                        <tbody>
                            <tr>
                                <td class="gettext">创建时间：</td>
                                <td rowspan="3">
                                    <input id="d421" class="Wdate wd175" name="startTime" type="text" value="@(ViewBag.StartTime)" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'%y-%M-%d'})" autocomplete="off" />
                                    -
                                    <input id="d422" class="Wdate wd175 m5_l" name="endTime" type="text" value="@(ViewBag.EndTime)" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'d421\')}'})" autocomplete="off" />
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <div class="AdvSearchfooter t_c">
                        <button id="search" class="btn btn-default btn-sm gettext" type="button">立即搜索</button>
                        <button id="cancel" data-dismiss="modal" class="btn btn-default btn-sm gettext" type="button">取消</button>
                    </div>
                </div>
            </div>
        </form>
        <div class="data-easyui data-scroll">
            <div class="data-view">
                <div class="data-div-view table-responsive">
                    <table class="table" id="pager"></table>
                </div>
            </div>
        </div>
    </div>
</section>
@section footerScript{
    <script type="text/javascript">

        var pageSize = 10;

        $(function () {
            FlashPay.UI.DataAutoHeight();

            doSearch();

            $("#btnSearch").click(function () {
                doSearch();
            });

            FlashPay.UI.Triggerbox({
                btnAdvSearch: '#AdvSearch',
                searchCallBack: function () {
                    window.currentPage = null;
                    doSearch();
                },
                cancelCallBack: function () {

                }
            });
        });

        function Tip_success(word) {
            FlashPay.UI.Tip_success(word);
        }

        $(".depositOrderdExport").click(function () {
            FlashPay.UI.Confirm({
                content: "下载存款记录需要花费大量时间,确认要下载吗？",
                ok: function () {

                    var cover = FlashPay.UI.Mask({
                        obj: $("body"),
                        opacity: 0.5
                    });

                    debugger;
                    var query = $("#formSearch").serializeJSON();


                    FlashPay.Util.Ajax({
                        url: '/Business/DepositOrderExport',
                        type: 'POST',
                        data: { query: query },
                        success: function (response) {
                            if (response.success) {
                                cover.Remove();

                                if (response.rows != null && response.rows.length > 0) {
                                    var body = '<table>';

                                    body += '<tr>';
                                    body += '<td>订单号</td>';
                                    body += '<td>商户订单号</td>';
                                    body += '<td>客户姓名</td>';
                                    body += '<td>订单金额</td>';
                                    body += '<td>支付金额</td>';
                                    body += '<td>结算金额</td>';
                                    body += '<td>收款卡卡号</td>';
                                    body += '<td>支付状态</td>';
                                    body += '<td>交易类型</td>';
                                    body += '<td>通知状态</td>';
                                    body += '<td>支付时间</td>';
                                    body += '<td>最后通知时间</td>';
                                    body += '<td>下单时间</td>';
                                    body += '</tr>';

                                    $.each(response.rows, function (i, item) {

                                        var statusResult = '';

                                        if (item.status == 1) {
                                            statusResult = '<span class="bold">未支付</span>';
                                        } else if (item.status == 2) {
                                            statusResult = '<span class="green bold">支付成功</span>';
                                        }

                                        var noticeResult = "";

                                        if (item.noticeStatus == 1) {
                                            noticeResult = '<span class="bold">未通知</span>';
                                        } else if (item.noticeStatus == 2) {
                                            noticeResult = '<span class="green bold">通知成功</span>';
                                        } else if (item.noticeStatus == 3) {
                                            noticeResult = "<span class='red bold' title='{0}'>通知失败</span>".format(item.noticeFail);
                                        } else if (item.noticeStatus == 4) {
                                            noticeResult = '<span class="bold">通知中</span>';
                                        }

                                        var transtypeResult = "";
                                        if (item.transtype == 3) {
                                            transtypeResult = '<span class="bold">网银转账</span>';
                                        } else if (item.transtype == 8) {
                                            transtypeResult = '<span class="green bold">支付宝转账</span>';
                                        } else if (item.transtype == 5) {
                                            transtypeResult = '<span class="green bold">微信转账</span>';
                                        } else if (item.transtype == 1) {
                                            transtypeResult = '<span class="green bold">云闪付</span>';
                                        }

                                        var clientCardName = "";
                                        if (!FlashPay.Util.isNullOrEmptySpance(item.clientCardName)) {
                                            clientCardName = item.clientCardName;
                                        }

                                        body += '<tr>';
                                        body += '<td>' + item._Id + '</td>';
                                        body += '<td>' + item.merchantOrderNo + '</td>';
                                        body += '<td>' + clientCardName + '</td>';
                                        body += '<td>' + item._DepositAmount + '</td>';
                                        body += '<td>' + item._PayAmount + '</td>';
                                        body += '<td>' + item._JieSuanAmount + '</td>';
                                        body += '<td>' + item.depositCardNumber + '</td>';
                                        body += '<td>' + statusResult + '</td>';
                                        body += '<td>' + transtypeResult + '</td>';
                                        body += '<td>' + noticeResult + '</td>';
                                        body += '<td>' + item._DepositDate + '</td>';
                                        body += '<td>' + item._NoticeLastTime + '</td>';
                                        body += '<td>' + item._CreatedDate + '</td>';
                                        body += '</tr>';
                                    });

                                    body += '</table>';

                                    var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
                                    excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">';
                                    //excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel';
                                    //excelFile += '; charset=UTF-8">';
                                    excelFile += "<head>";
                                    excelFile += "<!--[if gte mso 9]>";
                                    excelFile += "<xml>";
                                    excelFile += "<x:ExcelWorkbook>";
                                    excelFile += "<x:ExcelWorksheets>";
                                    excelFile += "<x:ExcelWorksheet>";
                                    excelFile += "<x:Name>";
                                    excelFile += "Sheet1";
                                    excelFile += "</x:Name>";
                                    excelFile += "<x:WorksheetOptions>";
                                    excelFile += "<x:DisplayGridlines/>";
                                    excelFile += "</x:WorksheetOptions>";
                                    excelFile += "</x:ExcelWorksheet>";
                                    excelFile += "</x:ExcelWorksheets>";
                                    excelFile += "</x:ExcelWorkbook>";
                                    excelFile += "</xml>";
                                    excelFile += "<![endif]-->";
                                    excelFile += "</head>";
                                    excelFile += "<body>";
                                    excelFile += body;
                                    excelFile += "</body>";
                                    excelFile += "</html>";

                                    var uri = window.URL.createObjectURL(new Blob([excelFile], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }));//'data:application/vnd.ms-excel;charset=utf-8,' + encodeURIComponent(excelFile);
                                    var link = document.createElement("a");
                                    link.href = uri;

                                    link.style = "visibility:hidden";
                                    link.download = response.statusCode + ".xls";

                                    document.body.appendChild(link);
                                    link.click();
                                    document.body.removeChild(link);
                                }
                                else {
                                    cover.Remove();
                                    FlashPay.UI.Tip_short_warning("暂无记录");
                                }

                            } else {
                                cover.Remove();
                                FlashPay.UI.Tip_short_warning("操作失败！" + response.errorMessage);
                            }
                        },
                        error: function (json) {
                            cover.Remove();
                            FlashPay.UI.Tip_warning("操作失败！请查看网络，请重试。");
                        }
                    });
                }
            });
        })

        function getParams() {
            var params = $("#formSearch").serializeJSON();
            return params;
        }

        function doSearch() {
            var frozenColumns = [[
                {
                    field: '_Id', title: "订单号", width: 75,
                    align: 'left',
                    formatter: function (val, item) {
                        if (!FlashPay.Util.isNullOrEmptySpance(val)) {
                            return '{0}'.format(val);
                        }
                    }
                },
                {
                    field: 'merchantOrderNo',
                    title: "商户订单号",
                    width: 200,
                    align: 'left',
                    formatter: function (val, item) {

                        if (!FlashPay.Util.isNullOrEmptySpance(val)) {

                            var result = '<span class="f_l">{0}</span>'.format(val);;

                            return result;

                        } else {
                            return "";
                        }
                    }
                }
            ]];

            var columns = [[
                {
                    field: 'clientCardName',
                    title: '客户姓名',
                    width: 75,
                    align: 'left'
                },
                {
                    field: '_DepositAmount',
                    title: '订单金额',
                    width: 75,
                    align: 'right'
                },
                {
                    field: '_PayAmount',
                    title: '支付金额',
                    width: 75,
                    align: 'right'
                },
                {
                    field: '_JieSuanAmount',
                    title: '结算金额',
                    width: 75,
                    align: 'right'
                },
                {
                    field: '_LiRunAmount',
                    title: '手续费',
                    width: 75,
                    align: 'right'
                },
                {
                    field: 'depositCardNumber',
                    title: '收款卡卡号',
                    width: 135,
                    align: 'left'
                },
                {
                    field: 'status',
                    title: '支付状态',
                    width: 75,
                    align: 'left',
                    formatter: function (val, item) {
                        var result = '';

                        if (val == 1) {
                            result = '<span class="bold">未支付</span>';
                        } else if (val == 2) {
                            result = '<span class="green bold">支付成功</span>';
                        }

                        return result;
                    }
                },
                {
                    field: 'transtype',
                    title: '交易类型',
                    width: 75,
                    align: 'left',
                    formatter: function (val, item) {
                        var result = "";

                        if (val == 3) {
                            result = '<span class="bold">网银转账</span>';
                        } else if (val == 8) {
                            result = '<span class="green bold">支付宝转账</span>';
                        } else if (val == 5) {
                            result = '<span class="green bold">微信转账</span>';
                        } else if (val == 1) {
                            result = '<span class="green bold">云闪付</span>';
                        }

                        return result;
                    }
                },
                {
                    field: 'noticeStatus',
                    title: '通知状态',
                    width: 75,
                    align: 'left',
                    formatter: function (val, item) {
                        /**
                         * 1、未通知
                         * 2、通知成功
                         * 3、通知失败
                         * 4、通知中
                         * */
                        var result = "";

                        if (val == 1) {
                            result = '<span class="bold">未通知</span>';
                        } else if (val == 2) {
                            result = '<span class="green bold">通知成功</span>';
                        } else if (val == 3) {
                            result = "<span class='red bold' title='{0}'>通知失败</span>".format(item.noticeFail);
                        } else if (val == 4) {
                            result = '<span class="bold">通知中</span>';
                        }

                        return result;
                    }
                },
                {
                    field: '_DepositDate',
                    title: '支付时间',
                    width: 120,
                    align: 'left'
                },
                {
                    field: '_NoticeLastTime',
                    title: '最后通知时间',
                    width: 120,
                    align: 'left'
                },
                {
                    field: '_CreatedDate',
                    title: '下单时间',
                    width: 120,
                    align: 'left'
                },
            ]];

            $("#pager").datagrid({
                fit: false,
                loadMsg: '数据加载中，请稍后……',
                method: "get",
                border: true,
                url: '/Business/DepositOrderQuery',
                queryParams: getParams(),
                pagination: true,
                pageSize: pageSize,
                pageList: [10, 15, 30, 50, 100, 1000],
                height: $(window).height() - 70,
                singleSelect: true,
                rownumbers: true,
                showFooter: true,
                idField: 'orderNo',
                onLoadSuccess: function () {
                    pageSize = $('#pager').datagrid('options').pageSize;
                },
                frozenColumns: frozenColumns,
                columns: columns
            });
        }
    </script>
}